package cn.akwangl.common;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.util.List;

/**
 * 通用分页响应.
 *
 * @author 阿坤同学
 * @date 2022/7/8 14:07
 * @since 0.0.7
 */
public class PagedGridResult {

    /**
     * 当前页数
     */
    private long page;

    /**
     * 分页大小
     */
    private long pageSize;

    /**
     * 总页数
     */
    private long total;
    /**
     * 总记录数
     */
    private long records;
    /**
     * 每行显示的内容
     */
    private List<?> rows;

    /**
     * 是否存在下一页
     */
    private boolean hasNext;

    /**
     * 是否存在上一页
     */
    private boolean hasPrevious;


    public long getPage() {
        return page;
    }

    public void setPage(long page) {
        this.page = page;
    }

    public long getPageSize() {
        return pageSize;
    }

    public void setPageSize(long pageSize) {
        this.pageSize = pageSize;
    }

    public long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public long getRecords() {
        return records;
    }

    public void setRecords(long records) {
        this.records = records;
    }

    public List<?> getRows() {
        return rows;
    }

    public void setRows(List<?> rows) {
        this.rows = rows;
    }

    public boolean isHasNext() {
        return hasNext;
    }

    public void setHasNext(boolean hasNext) {
        this.hasNext = hasNext;
    }

    public boolean isHasPrevious() {
        return hasPrevious;
    }

    public void setHasPrevious(boolean hasPrevious) {
        this.hasPrevious = hasPrevious;
    }

    public static PagedGridResult createPagedGridResult(Page page) {
        PagedGridResult pagedGridResult = new PagedGridResult();
        pagedGridResult.setPage(page.getCurrent());
        pagedGridResult.setPageSize(page.getSize());
        pagedGridResult.setTotal(page.getPages());
        pagedGridResult.setRecords(page.getTotal());
        pagedGridResult.setRows(page.getRecords());
        pagedGridResult.setHasNext(page.hasNext());
        pagedGridResult.setHasPrevious(page.hasPrevious());
        return pagedGridResult;
    }
}
